package com.zb.sannuo.thereport.controller;

import com.zb.sannuo.common.domain.search.MonthlyDataReports;
import com.zb.sannuo.common.domain.vo.ReportVo;
import com.zb.sannuo.common.result.Result;
import com.zb.sannuo.common.result.ResultCode;
import com.zb.sannuo.thereport.service.MonthlyDataService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;

@RestController
@RequestMapping("/reports")
@Api(value = "报表管理模块",description = "月度数据报表")
@CrossOrigin
public class MonthlyDataController {

    @Resource
    private MonthlyDataService monthlyDataServiceImpl;

    @ApiOperation(value = "查询每日检测人数",notes = "查询每日检测人数",httpMethod = "GET")
    @RequestMapping(value = "monthlyData",method = RequestMethod.GET)
    public Result queryMonthlyData(ReportVo reportVo) throws Exception{
        Calendar calendar = Calendar.getInstance(Locale.CANADA);
        int actualMaximum = calendar.getActualMaximum(Calendar.DATE);
        Integer[] integers = new Integer[actualMaximum];
        Integer[] integers1 = new Integer[actualMaximum];
        List<MonthlyDataReports> data = monthlyDataServiceImpl.queryMonthlyData(reportVo);
        for (int i =1; i<= actualMaximum; i++){
            boolean bo = true;
            integers1[i-1] = i;
            MonthlyDataReports monthlyDataReports = null;
            integers1[i-1] = i;
            for (MonthlyDataReports reports : data) {
                System.out.println(reports);
                if (reports.getTestingTime() == i){
                    integers[i-1] = reports.getTestingNumbers();
                    bo = false;
                }
            }
            if (bo){
                integers[i-1] = 0;
            }
        }


        HashMap<String, Integer[]> map = new HashMap<>();
        map.put("integers",integers);
        map.put("integers1",integers1);

        return Result.ok(ResultCode.SUCCESS,map);
    }
}
